反馈建议', '您对Tools工具箱的建议和意见,以及使用过程中遇到的问题,可以及时的反馈给我们。') ); //初始化 $lockfile = ''; //tools锁存放位置 $action = ''; $target_fsockopen = '0'; //使用何种方式进行连接服务器 0=域名, 1=IP (使用IP方式需要保证IP地址可以正常访问到您的站点) $alertmsg = ' onclick="alert(\'点击确定开始运行,可能需要一段时间,请稍候\');"'; //释放变量到全局 foreach(array('_COOKIE', '_POST', '_GET') as $_request) { foreach($$_request as $_key => $_value) { ($_key{0} != '_' && $_key != 'tool_password' && $_key != 'lockfile') && $$_key = taddslashes($_value); } } //判断文件位置 $whereis = getplace(); if($whereis == 'is_dz' && !defined('DISCUZ_ROOT')) { define('DISCUZ_ROOT', TOOLS_ROOT); } if(!$whereis && !in_array($whereis, array('is_dz', 'is_uc', 'is_uch', 'is_ss', 'is_ec', 'is_ecm'))) { $alertmsg = ''; errorpage('工具箱必须放在Discuz!、UCenter、UCente Home、SupeSite、ECShop或者ECmall的根目录下才能正常使用.'); } //工具箱是否锁定 if(@file_exists($lockfile)) { $alertmsg = ''; errorpage("
工具箱已关闭,如需开启只要通过 FTP 删除 $lockfile 文件即可!
"); } elseif ($tool_password == ''){ $alertmsg = ''; errorpage('
工具箱密码默认为空,第一次使用前请您修改本文件中$tool_password设置密码!
'); } //登陆 if($action == 'login') { setcookie('toolpassword',$toolpassword, 0); echo ''; errorpage("
请稍等,程序登录中!
"); } if(isset($toolpassword)) { if($toolpassword != $tool_password) { $alertmsg = ''; //bug 有点多余? errorpage("login"); } } else { $alertmsg = ''; errorpage("login"); } $conf = getdbcfg(); //流程开始 //单独放在一个文件里编译 多人编写,发布的时候 组合成一个文件 if($action == 'all_repair') {//修复数据库开始 //连接配置文件 if(@!require_once($cfgfile)) { htmlheader(); cexit("

请先上传config文件以保证您的数据库能正常链接!

"); } //初始化数据库连接帐号 getdbcfg(); //连接数据库 mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname); $counttables = $oktables = $errortables = $rapirtables = 0; if($check) { $tables = mysql_query("SHOW TABLES"); if(!$nohtml) { echo ""; } if($iterations) { $iterations --; } while($table = mysql_fetch_row($tables)) { $counttables += 1; $answer = checktable($table[0],$iterations); if(!$nohtml) { echo " "; } elseif (!$simple) { flush(); } } if(!$nohtml) { echo ""; } if($simple) { htmlheader(); echo '

检查修复数据库

检查结果:
检查表(张)正常表(张)错误表(张)错误数(个)
'.$counttables.''.$oktables.''.$rapirtables.''.$errortables.'

检查结果没有错误后请返回工具箱首页反之则继续修复

继续修复    返回首页

'; specialdiv(); } } else { htmlheader(); echo "

检查修复数据库

操作提示:
操作:
"; specialdiv(); } htmlfooter(); }elseif($action == 'all_restore') {//导入数据库备份 ob_implicit_flush(); //不同的程序存放备份文件的目录是不同的 $backdirarray = array( 'is_dz'=>'forumdata', 'is_uc'=>'data/backup', 'is_uch'=>'data', 'is_ss'=>'data' ); //初始化数据库连接帐号 getdbcfg(); //连接数据库 mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname); $my_version = mysql_get_server_info(); if($my_version > '4.1'){ $serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results='.$dbcharset.', character_set_client=binary' : ''; $serverset .=$my_version > '5.0.1' ? ((empty($serverset))? '' : ',').'sql_mode=\'\'' : ''; $serverset && mysql_query("SET $serverset"); } if(!get_cfg_var('register_globals')) { @extract($HTTP_GET_VARS); } $sqldump = ''; htmlheader(); ?>

数据库恢复实用工具

操作提示:"; if($file) { if(strtolower(substr($file, 0, 7)) == "http://") { echo "从远程数据库恢复数据 - 读取远程数据:

"; echo "从远程服务器读取文件 ... "; $sqldump = @fread($fp, 99999999); @fclose($fp); if($sqldump) { echo "成功

"; } elseif (!$multivol) { cexit("失败

无法恢复数据"); } } else { echo "
从本地恢复数据 - 检查数据文件:

"; if(file_exists($file)) { echo "数据文件 $file 存在检查 ... 成功

"; } elseif (!$multivol) { cexit("数据文件 $file 存在检查 ... 失败


无法恢复数据
"); } if(is_readable($file)) { echo "数据文件 $file 可读检查 ... 成功

"; @$fp = fopen($file, "r"); @flock($fp, 3); $sqldump = @fread($fp, filesize($file)); @fclose($fp); echo "从本地读取数据 ... 成功

"; } elseif (!$multivol) { cexit("数据文件 $file 可读检查 ... 失败


无法恢复数据"); } } if($multivol && !$sqldump) { cexit("分卷备份范围检查 ... 成功

恭喜您,数据已经全部成功恢复!安全起见,请务必删除本程序."); } echo "数据文件 $file 格式检查 ... "; if($whereis == 'is_uc') { $identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($sqldump, 0, 256)))); $method = 'multivol'; $volume = $identify[2]; }else{ @list(,,,$method, $volume) = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", preg_replace("/^(.+)/", "\\1", substr($sqldump, 0, 256))))); } if($method == 'multivol' && is_numeric($volume)) { echo "成功

"; } else { cexit("失败

数据非 Discuz! 分卷备份格式,无法恢复"); } if($onlysave == "yes") { echo "将数据文件保存到本地服务器 ... "; $filename = TOOLS_ROOT.'./'.$backdirarray[$whereis].strrchr($file, "/"); @$filehandle = fopen($filename, "w"); @flock($filehandle, 3); if(@fwrite($filehandle, $sqldump)) { @fclose($filehandle); echo "成功

"; } else { @fclose($filehandle); die("失败

无法保存数据"); } echo "成功

恭喜您,数据已经成功保存到本地服务器 $filename.安全起见,请务必删除本程序."; } else { $sqlquery = splitsql($sqldump); echo "拆分操作语句 ... 成功

"; unset($sqldump); echo "正在恢复数据,请等待 ... "; foreach($sqlquery as $sql) { $dbversion = mysql_get_server_info(); $sql = syntablestruct(trim($sql), $dbversion > '4.1', $dbcharset); if(trim($sql)) { @mysql_query($sql); } } if($auto == 'off'){ $nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file); cexit(""); } else { $nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file); echo ""; redirect("?action=all_restore&file=$nextfile&multivol=yes"); } } } else { $exportlog = array(); if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) { $dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]); while($entry = $dir->read()) { $entry = "./".$backdirarray[$whereis]."/$entry"; if(is_file($entry) && preg_match("/\.sql/i", $entry)) { $filesize = filesize($entry); $fp = @fopen($entry, 'rb'); @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256)))); @fclose ($fp); if(preg_match("/\-1.sql/i", $entry) || $identify[3] == 'shell'){ $exportlog[$identify[0]] = array( 'version' => $identify[1], 'type' => $identify[2], 'method' => $identify[3], 'volume' => $identify[4], 'filename' => $entry, 'size' => $filesize); } } elseif (is_dir($entry) && preg_match("/backup\_/i", $entry)) { $bakdir = dir($entry); while($bakentry = $bakdir->read()) { $bakentry = "$entry/$bakentry"; if(is_file($bakentry)){ @$fp = fopen($bakentry, 'rb'); @$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256)))); @fclose ($fp); if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') { $identify['bakentry'] = $bakentry; } } } if(preg_match("/backup\_/i", $entry)){ $exportlog[filemtime($entry)] = array( 'version' => $bakidentify[1], 'type' => $bakidentify[2], 'method' => $bakidentify[3], 'volume' => $bakidentify[4], 'bakentry' => $identify['bakentry'], 'filename' => $entry); } } } $dir->close(); } else { echo 'error'; } krsort($exportlog); reset($exportlog); $exportinfo = '
数据备份信息
'; foreach($exportlog as $dateline => $info) { $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知'; switch($info['type']) { case 'full': $info['type'] = '全部备份'; break; case 'standard': $info['type'] = '标准备份(推荐)'; break; case 'mini': $info['type'] = '最小备份'; break; case 'custom': $info['type'] = '自定义备份'; break; } $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : ''; $info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell'; $info['url'] = str_replace(".sql", '', str_replace("-$info[volume].sql", '', substr(strrchr($info['filename'], "/"), 1))); $exportinfo .= "\n". "\n". "\n". "\n". "\n"; if($info['bakentry']){ $exportinfo .= "\n". "\n\n"; } else { $exportinfo .= "\n". "\n\n"; } } $exportinfo .= '
   数据库文件夹
备份项目版本 时间类型 查看操作
".$info['url']."$info[version]$info[dateline]$info[type]查看[全部导入]
查看[全部导入]
'; echo $exportinfo; unset($exportlog); unset($exportinfo); echo "
"; //查看目录里的备份文件列表,一级目录下 if(!empty($filedirname)){ $exportlog = array(); if(is_dir(TOOLS_ROOT.'./'.$backdirarray[$whereis])) { $dir = dir(TOOLS_ROOT.'./'.$backdirarray[$whereis]); while($entry = $dir->read()) { $entry = "./".$backdirarray[$whereis]."/$entry"; if(is_file($entry) && preg_match("/\.sql/i", $entry) && preg_match("/$filedirname/i", $entry)) { $filesize = filesize($entry); @$fp = fopen($entry, 'rb'); @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256)))); @fclose ($fp); $exportlog[$identify[0]] = array( 'version' => $identify[1], 'type' => $identify[2], 'method' => $identify[3], 'volume' => $identify[4], 'filename' => $entry, 'size' => $filesize); } } $dir->close(); } else { } krsort($exportlog); reset($exportlog); $exportinfo = ''; foreach($exportlog as $dateline => $info) { $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知'; switch($info['type']) { case 'full': $info['type'] = '全部备份'; break; case 'standard': $info['type'] = '标准备份(推荐)'; break; case 'mini': $info['type'] = '最小备份'; break; case 'custom': $info['type'] = '自定义备份'; break; } $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : ''; $info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell'; $exportinfo .= "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n\n"; } $exportinfo .= '
   数据库文件列表
文件名版本 时间类型 大小方式 卷号操作
".substr(strrchr($info['filename'], "/"), 1)."$info[version]$info[dateline]$info[type]".get_real_size($info[size])."$info[method]$info[volume][导入]
'; echo $exportinfo; } // 查看目录里的备份文件列表, 二级目录下,其中二级目录是随机产生的 if(!empty($bakdirname)){ $exportlog = array(); $filedirname = TOOLS_ROOT.'./'.$backdirarray[$whereis].'/'.$bakdirname; if(is_dir($filedirname)) { $dir = dir($filedirname); while($entry = $dir->read()) { $entry = $filedirname.'/'.$entry; if(is_file($entry) && preg_match("/\.sql/i", $entry)) { $filesize = filesize($entry); @$fp = fopen($entry, 'rb'); @$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256)))); @fclose ($fp); $exportlog[$identify[0]] = array( 'version' => $identify[1], 'type' => $identify[2], 'method' => $identify[3], 'volume' => $identify[4], 'filename' => $entry, 'size' => $filesize); } } $dir->close(); } krsort($exportlog); reset($exportlog); $exportinfo = ''; foreach($exportlog as $dateline => $info) { $info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知'; switch($info['type']) { case 'full': $info['type'] = '全部备份'; break; case 'standard': $info['type'] = '标准备份(推荐)'; break; case 'mini': $info['type'] = '最小备份'; break; case 'custom': $info['type'] = '自定义备份'; break; } $info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : ''; $info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell'; $exportinfo .= "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n\n"; } $exportinfo .= '
   数据库文件列表
文件名版本 时间类型 大小方式 卷号操作
".substr(strrchr($info['filename'], "/"), 1)."$info[version]$info[dateline]$info[type]".get_real_size($info[size])."$info[method]$info[volume][导入]
'; echo $exportinfo; } echo "
"; cexit(""); } } elseif ($action == 'all_runquery') {//运行sql //初始化数据库连接帐号 getdbcfg(); //连接数据库 mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname); $my_version = mysql_get_server_info(); if($my_version > '4.1'){ $serverset = 'character_set_connection=gbk, character_set_results=gbk, character_set_client=binary'; $serverset .=$my_version > '5.0.1' ? ((empty($serverset))? '' : ',').'sql_mode=\'\'' : ''; $serverset && mysql_query("SET $serverset"); } if(!empty($_POST['sqlsubmit']) && $_POST['queries']) { $sqlquery = splitsql(str_replace(array(' cdb_', ' {tablepre}', ' `cdb_'), array(' '.$tablepre, ' '.$tablepre, ' `'.$tablepre), $queries)); $affected_rows = 0; foreach($sqlquery as $sql) { $sql = syntablestruct(trim($sql), $my_version > '4.1', $dbcharset); if(trim($sql) != '') { mysql_query(stripslashes($sql)); if($sqlerror = mysql_error()) { break; } else { $affected_rows += intval(mysql_affected_rows()); } } } errorpage($sqlerror? $sqlerror : "数据库升级成功,影响行数:  $affected_rows",'数据库升级'); if(strpos($queries,'settings') && $whereis == 'is_dz') { require_once './include/cache.func.php'; updatecache('settings'); } } htmlheader(); echo "

数据库升级

请将数据库升级语句粘贴在下面
"; if($whereis == 'is_dz') { echo ""; } echo "


"; htmlfooter(); }elseif($action == 'all_checkcharset') {//编码检测 $maincharset = $dbcharset; $conn = mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname); $my_version = mysql_get_server_info(); if($my_version > '4.1') { if($repairsubmit){ htmlheader(); echo '

编码检查

'; echo "
操作提示:
"; if(!is_array($repair)){ $repair=array(); show_tools_message('没有修复任何字段', 'tools.php?action=all_checkcharset'); htmlfooter(); exit; } foreach($repair as $key=>$value){ $tableinfo = ''; $tableinfo = explode('|', $value); $tablename = $tableinfo[0]; $collation = $tableinfo[1]; $maincharset = $tableinfo[2]; $query = mysql_query("SHOW CREATE TABLE $tablename"); while($createsql = mysql_fetch_array($query)){ $colationsql = explode(",\n",$createsql[1]); foreach($colationsql as $numkey=>$collsql){ if(strpos('ddd'.$collsql,'`'.$collation.'`') == 5){ $collsql = preg_replace("/character set (?!latin1)(.+?)collate (.+?)\b/","character set $maincharset",$collsql); $changesql = 'alter table '.$tablename.' change `'.$collation.'` '.$collsql; mysql_query($changesql); } } } //print_r($changesql); } show_tools_message('修复完毕', 'tools.php?action=all_checkcharset'); htmlfooter(); exit; }else{ $sql = "SELECT `TABLE_NAME` AS `Name`, `TABLE_COLLATION` AS `Collation` FROM `information_schema`.`TABLES` WHERE ".(strpos("php".PHP_OS,"WIN")?"":"BINARY")."`TABLE_SCHEMA` IN ('$dbname') AND TABLE_NAME like '$tablepre%'"; $query = @mysql_query($sql); $dbtable = array(); $chars = array('gbk'=>0,'big5'=>0,'utf8'=>0,'latin1'=>0);//各个编码的字段数量 if(!$query){ htmlheader(); errorpage('您当前的数据库版本无法检查字符集设定,可能是由于版本过低不支持检查语句导致', '', 0, 0); htmlfooter(); exit; } while($dbdetail = mysql_fetch_array($query)){ $dbtable[$dbdetail["Name"]]["Collation"] = pregcharset($dbdetail["Collation"],1); //获得每个表的编码 $dbtable[$dbdetail["Name"]]["tablename"] = $dbdetail["Name"]; //数据库所有的表名 $tablequery = mysql_query("SHOW FULL FIELDS FROM `".$dbdetail["Name"]."`");//取出每个表的结构 while($tables= mysql_fetch_array($tablequery)){ if(!empty($tables["Collation"])) { $collcharset = pregcharset($tables["Collation"], 0); $tableschar[$collcharset][$dbdetail["Name"]][] = $tables["Field"]; $chars[pregcharset($tables["Collation"], 0)]++; } } } } } htmlheader(); echo '

编码检查

'; echo "
操作提示:
"; if($my_version > '4.1') { echo'
数据库('.$dbname.')的字符集统计:
gbk字段big5字段utf8字段latin1字段
'.$chars[gbk].' '.$chars[big5].' '.$chars[utf8].' '.$chars[latin1].' 
下列字段可能存在编码设置异常:
'; ?> $num) { if ($char != $maincharset) { if(is_array($tableschar[$char])) { echo '
'; foreach($tableschar[$char] as $tablename => $fields) { echo''; foreach($fields as $collation) { echo''; } echo '
全选 '.$tablename.' 表异常的字段 编码
'; echo ''.$collation.''.$char.'
'; } } } } echo '
'; echo'


'; }else { errorpage('MySQL数据库版本在4.1以下,没有字符集设定,无需检测', '', 0, 0); } htmlfooter(); } elseif ($action == 'dz_doctor') {//论坛医生 //论坛医生功能 htmlheader(); //检测DZ的目录 if($whereis != 'is_dz') { cexit("

Tools放在论坛的目录中才可以使用本功能

"); } echo ""; function create_checkfile() { global $dir; $fp = @fopen('./forumdata/checkfile.php',w); $includedir = $dir != './' ? str_replace('forumdata/','./',$dir) : '../'; $content = ""; fwrite($fp, $content); fclose($fp); } function http_fopen($host, $path, $port="80") { global $target_fsockopen; $conn_host = $target_fsockopen == 1 ? gethostbyname($host) : $host; $conn_port = $port; $abs_url = "http://$host:$port$path"; $query="GET $abs_url HTTP/1.0\r\n". "HOST:$host:$port\r\n". "User-agent:PHP/class http 0.1\r\n". "\r\n"; $fp=fsockopen($conn_host, $conn_port); if(!$fp){ return false; } fputs($fp,$query); //得到返回的结果 $contents = ""; while (!feof($fp)) { $contents .= fread($fp, 1024); } fclose($fp); $array = split("\n\r", $contents, "2"); return trim($array[1]); } //论坛模式样式代码变量 $ok_style_s = '[color=RoyalBlue][b]'; $error_style_s = '[color=Red][b]'; $style_e = '[/b][/color]'; $title_style_s = '[b]'; $title_style_e = '[/b]'; $phpfile_array = array('discuzroot', 'templates', 'cache');//文件错误检查中的目录及对应名称($dir_array) $dir_array = array('论坛根目录', '模板缓存目录(forumdata/templates)', '其它缓存目录(forumdata/cache)'); $doctor_top = count($phpfile_array) - 1; //$doctor_step = isset($_REQUEST['doctor_step']) ? intval($_REQUEST['doctor_step']) : ''; if(@!include("./config.inc.php")) { if(@!include("./config.php")) { cexit("

请先上传config文件以保证您的数据库能正常链接!

"); } } if($doctor_step == $doctor_top) { //检查Config.inc.php文件配置 $carray = $clang = $comment = array(); $doctor_config = $doctor_config_db = ''; $configfilename = file_exists('./config.inc.php') ? './config.inc.php' : './config.php'; $fp = @fopen($configfilename, 'r'); $configfile = @fread($fp, @filesize($configfilename)); @fclose($fp); preg_match_all("/[$]([\w\[\]\']+)\s*\=\s*[\"']?(.*?)[\"']?;/is", $configfile, $cmatch); foreach($cmatch[1] as $key => $var) { if(!in_array($var, array('database','adminemail','admincp'))) { $carray[$var] = $cmatch[2][$key]; } } $clang = array( 'dbhost' => '数据库服务器', 'dbuser' => '数据库用户名', 'dbpw' => '数据库密码', 'dbname' => '数据库名', 'pconnect' => '数据库是否持久连接', 'cookiepre' => 'cookie 前缀', 'cookiedomain' => 'cookie 作用域', 'cookiepath' => 'cookie 作用路径', 'tablepre' => '表名前缀', 'dbcharset' => 'MySQL链接字符集', 'charset' => '论坛字符集', 'headercharset' => '强制论坛页面使用默认字符集', 'tplrefresh' => '论坛风格模板自动刷新开关', 'forumfounders' => '论坛创始人uid', 'dbreport' => '是否发送错误报告给管理员', 'errorreport' => '是否屏蔽程序错误信息', 'attackevasive' => '论坛防御级别', 'admincp[\'forcesecques\']' => '管理人员是否必须设置安全提问才能进入系统设置', 'admincp[\'checkip\']' => '后台管理操作是否验证管理员的 IP', 'admincp[\'tpledit\']' => '是否允许在线编辑论坛模板', 'admincp[\'runquery\']' => '是否允许后台运行 SQL 语句', 'admincp[\'dbimport\']' => '是否允许后台恢复论坛数据', ); $comment = array( 'pconnect' => '非持久连接', 'cookiepre' => '不检测', 'cookiepath' => '不检测', 'charset' => '不检测', 'adminemail' => '不检测', 'admincp' => '非设置项', ); @mysql_connect($carray['dbhost'], $carray['dbuser'], $carray['dbpw']) or $mysql_errno = mysql_errno(); !$mysql_errno && @mysql_select_db($carray['dbname']) or $mysql_errno = mysql_errno(); $comment_error = "{$error_style_s}出错{$style_e}"; if ($mysql_errno == '2003') { $comment['dbhost'] = "{$error_style_s}端口设置出错{$style_e}"; } elseif ($mysql_errno == '2005') { $comment['dbhost'] = $comment_error; } elseif ($mysql_errno == '1045') { $comment['dbuser'] = $comment_error; $comment['dbpw'] = $comment_error; } elseif ($mysql_errno == '1049') { $comment['dbname'] = $comment_error; } elseif (!empty($mysql_errno)) { $comment['dbhost'] = $comment_error; $comment['dbuser'] = $comment_error; $comment['dbpw'] = $comment_error; $comment['dbname'] = $comment_error; } $comment['pconnect'] = '非持久链接'; $carray['pconnect'] == 1 && $comment['pconnect'] = '持久连接'; if ($carray['cookiedomain'] && substr($carray['cookiedomain'], 0, 1) != '.') { $comment['cookiedomain'] = "{$error_style_s}请以 . 开头,不然同步登录会出错{$style_e}"; } (!$mysql_errno && !mysql_num_rows(mysql_query('SHOW TABLES LIKE \''.$carray['tablepre'].'posts\''))) && $comment['tablepre'] = $comment_error; if (!$comment['tablepre'] && !$mysql_errno && @mysql_get_server_info() > '4.1') { $tableinfo = loadtable('threads'); $dzdbcharset = substr($tableinfo['subject']['Collation'], 0, strpos($tableinfo['subject']['Collation'], '_')); if(!$carray['dbcharset'] && in_array(strtolower($carray['charset']), array('gbk', 'big5', 'utf-8'))) { $ckdbcharset = str_replace('-', '', $carray['charset']); } else { $ckdbcharset = $carray['dbcharset']; } if ($dzdbcharset != $ckdbcharset && $ckdbcharset != '') { $carray['dbcharset'] .= $error_style_s.'出错,您的论坛数据库字符集为 '.$dzdbcharset.' ,请将本项设置成 '.$dzdbcharset.$style_e; } } if(!in_array($carray['charset'],array('gbk', 'big5', 'utf-8'))) { $carray['charset'] .= $error_style_s." 出错,目前字符集只支持'gbk', 'big5', 'utf-8'".$style_e; } if ($carray['headercharset'] == 0) { $comment['headercharset'] = $title_style_s.'未开启'.$title_style_e; } else { $comment['headercharset'] = $ok_style_s.'开启'.$style_e; } if ($carray['tplrefresh'] == 0) { $comment['tplrefresh'] = $title_style_s.'关闭'.$title_style_e; } else { $comment['tplrefresh'] = $ok_style_s.'开启'.$style_e; } if (preg_match('/[^\d,]/i', str_replace(' ', '', $carray['forumfounders']))) { $comment['forumfounders'] = $error_style_s.'出错:含有非法字符,该项设置只能含有数字和半角逗号 ,'.$style_e; } elseif(!$comment['tablepre'] && !$mysql_errno) { if ($carray['forumfounders']) { $founderarray = explode(',', str_replace(' ', '', $carray['forumfounders'])); $adminids = $notadminids = ''; $notadmin = 0; foreach($founderarray as $fdkey) { if (@mysql_result(@mysql_query("SELECT adminid FROM {$carray[tablepre]}members WHERE uid = '$fdkey' LIMIT 1"), 0) == 1) { $isadmin ++; $iscomma = $isadmin > 1 ? ',' : ''; $adminids .= $iscomma.$fdkey; } else { $notadmin ++; $notcomma = $notadmin > 1 ? ',' : ''; $notadminids .= $notcomma.$fdkey; } } if (!$isadmin) { $comment['forumfounders'] = $error_style_s.'出错:创始人中无管理员'.$style_e; } elseif ($notadmin) { $comment['forumfounders'] = $error_style_s.'警告:创始人中有非管理员,uid如下:'.$notadminids.$style_e; } } else { $comment['forumfounders'] = $error_style_s.'警告:创始人设置为空,多个管理员将可能有安全问题'.$style_e; } } $comment['dbreport'] = $carray['dbreport'] == 0 ? '不发送错误报告' : '发送错误报告'; $comment['errorreport'] = $carray['errorreport'] == 1 ? '屏蔽程序错误' : '不屏蔽程序错误'; if (preg_match('/[^\d|]/i', str_replace(' ', '', $carray['attackevasive']))) { $carray['attackevasive'] .= $error_style_s.'出错:含有非法字符,该项设置只能含有数字和半角逗号,'.$style_e; } else { if (preg_match('/[8]/i', $carray['attackevasive']) && @mysql_result(@mysql_query("SELECT COUNT(*) FROM {$carray[tablepre]}members")) < 1) { $carray['attackevasive'] .= $error_style_s.'出错:您设置了回答问题(8),但未添加验证问题和答案 ,'.$style_e; } } $comment_admincp_error = "否 > {$error_style_s}警告:有安全隐患{$style_e}"; $comment_admincp_ok = "是 > {$error_style_s}警告:有安全隐患{$style_e}"; if ($carray['admincp[\'forcesecques\']'] == 1) { $comment['admincp[\'forcesecques\']'] = "{$ok_style_s}是{$style_e}"; } else { $comment['admincp[\'forcesecques\']'] = $comment_admincp_error; } if ($carray['admincp[\'checkip\']'] == 0) { $comment['admincp[\'checkip\']'] = $comment_admincp_error; } else { $comment['admincp[\'checkip\']'] = "{$ok_style_s}是{$style_e}"; } if ($carray['admincp[\'tpledit\']'] == 1) { $comment['admincp[\'tpledit\']'] = $comment_admincp_ok; } else { $comment['admincp[\'tpledit\']'] = "{$title_style_s}否{$title_style_e}"; } if ($carray['admincp[\'runquery\']'] == 1) { $comment['admincp[\'runquery\']'] = $comment_admincp_ok; } else { $comment['admincp[\'runquery\']'] = "{$title_style_s}否{$title_style_e}"; } if ($carray['admincp[\'dbimport\']'] == 1) { $comment['admincp[\'dbimport\']'] = $comment_admincp_ok; } else { $comment['admincp[\'dbimport\']'] = "{$title_style_s}否{$title_style_e}"; } foreach($carray as $key => $keyfield) { $clang[$key] == '' && $clang[$key] = ' '; strpos('comma'.$comment[$key], '警告') && $comment[$key] = $comment[$key]; strpos('comma'.$comment[$key], '出错') && $comment[$key] = $comment[$key]; $comment[$key] == '' && $comment[$key] = "{$ok_style_s}正常{$style_e}"; if(in_array($key, array('dbuser', 'dbpw'))) { $keyfield = '**隐藏**'; } $keyfield == '' && $keyfield = '空'; if(!in_array($key, array('dbhost','dbuser','dbpw','dbname'))) { if(in_array($key, array('pconnect', 'headercharset', 'tplrefresh', 'dbreport', 'errorreport', 'admincp[\'forcesecques\']', 'admincp[\'checkip\']', 'admincp[\'tpledit\']', 'admincp[\'runquery\']', 'admincp[\'dbimport\']'))) { $doctor_config .= "\n\t{$title_style_s}$key{$title_style_e} ---> $clang[$key] ---> $comment[$key]\n"; } elseif(in_array($key, array('cookiepre', 'cookiepath', 'cookiedomain', 'charset', 'dbcharset', 'attackevasive'))) { $doctor_config .= "\n\t{$title_style_s}$key{$title_style_e} ---> $clang[$key] ---> $keyfield\n"; } else { $doctor_config .= "\n\t{$title_style_s}$key{$title_style_e} ---> $clang[$key] ---> $keyfield ---> $comment[$key]\n"; } } else { if(strstr($comment[$key], '出错')) { strstr($doctor_config_db, '正常') && $doctor_config_db = ''; $doctor_config_db .= "{$title_style_s}$key{$title_style_e} ---> $clang[$key] ---> $comment[$key]"; } else { if(empty($doctor_config_db)) { $doctor_config_db ="\n\t{$ok_style_s}数据库正常链接.{$style_e}"; } } } } $doctor_config = "\n".$doctor_config_db.$doctor_config; //校验环境是否支持DZ/SS,查看数据库和表的字符集,敏感信息 charset,dbcharset, php,mysql,zend,php 短标记 $msg = ''; $curr_os = PHP_OS; if(!function_exists('mysql_connect')) { $curr_mysql = $error_style_s.'不支持'.$style_e; $msg .= "您的服务器不支持MySql数据库,无法安装论坛程序"; $quit = TRUE; } else { if(@mysql_connect($dbhost, $dbuser, $dbpw)) { $curr_mysql = mysql_get_server_info(); } else { $curr_mysql = $ok_style_s.'支持'.$style_e; } } if(function_exists('mysql_connect')) { $authkeylink = @mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname, $authkeylink); $authkeyresult = mysql_result(mysql_query("SELECT `value` FROM {$tablepre}settings WHERE `variable`='authkey'", $authkeylink), 0); if($authkeyresult) { $authkeyexist = $ok_style_s.'存在'.$style_e; } else { $authkeyexist = $error_style_s.'不存在'.$style_e; } } $curr_php_version = PHP_VERSION; if($curr_php_version < '4.0.6') { $msg .= "您的 PHP 版本小于 4.0.6, 无法使用 Discuz! / SuperSite。"; } if(ini_get('allow_url_fopen')) { $allow_url_fopen = $ok_style_s.'允许'.$style_e; } else { $allow_url_fopen = $title_style_s.'不允许'.$title_style_e; } $max_execution_time = get_cfg_var('max_execution_time'); $max_execution_time == 0 && $max_execution_time = '不限制'; $memory_limit = get_cfg_var('memory_limit'); $curr_server_software = $_SERVER['SERVER_SOFTWARE']; if(function_exists('ini_get')) { if(!@ini_get('short_open_tag')) { $curr_short_tag = $title_style_s.'不允许'.$title_style_e; $msg .='请将 php.ini 中的 short_open_tag 设置为 On,否则无法使用论坛。'; } else { $curr_short_tag = $ok_style_s.'允许'.$style_e; } if(@ini_get(file_uploads)) { $max_size = @ini_get(upload_max_filesize); $curr_upload_status = '您可以上传附件的最大尺寸: '.$max_size; } else { $msg .= "附件上传或相关操作被服务器禁止。"; } } else { $msg .= 'php.ini中禁用了ini_get()函数.部分环境参数无法检测.'; } if(!defined('OPTIMIZER_VERSION')) define('OPTIMIZER_VERSION','没有安装或版本较低'); if(OPTIMIZER_VERSION < 3.0) { $msg .="您的ZEND版本低于3.0,将无法使用SuperSite."; } //临时目录的检查 if(@is_writable(@ini_get('upload_tmp_dir'))){ $tmpwritable = $ok_style_s.'可写'.$style_e; } elseif(!@ini_get('upload_tmp_dir') & @is_writable($_ENV[TEMP])) { $tmpwritable = $ok_style_s.'可写'.$style_e; } else { $tmpwritable = $title_style_s.'不可写'.$title_style_e; } if(@ini_get('safe_mode') == 1) { $curr_safe_mode = $ok_style_s.'开启'.$style_e; } else { $curr_safe_mode = $title_style_s.'关闭'.$title_style_e; } if(@diskfreespace('.')) { $curr_disk_space = intval(diskfreespace('.') / (1024 * 1024)).'M'; } else { $curr_disk_space = '无法检测'; } if(function_exists('xml_parser_create')) { $curr_xml = $ok_style_s.'可用'.$style_e; } else { $curr_xml = $title_style_s.'不可用'.$title_style_e; } if(function_exists('file')) { $funcexistfile = $ok_style_s.'存在'.$style_e; } else { $funcexistfile = $title_style_s.'不存在'.$title_style_e; } if(function_exists('fopen')) { $funcexistfopen = $ok_style_s.'存在'.$style_e; } else { $funcexistfopen = $title_style_s.'不存在'.$title_style_e; } if(@ini_get('display_errors')) { $curr_display_errors = $ok_style_s.'开启'.$style_e; } else { $curr_display_errors = $title_style_s.'关闭'.$title_style_e; } if(!function_exists('ini_get')) { $curr_display_errors = $tmpwritable = $curr_safe_mode = $curr_upload_status = $curr_short_tag = '无法检测'; } //目录权限检查 $envlogs = array(); $entryarray = array ( 'attachments', 'forumdata', 'forumdata/threadcaches', 'forumdata/logs', 'forumdata/templates', 'forumdata/cache', 'customavatars', 'forumdata/viewcount.log', 'forumdata/dberror.log', 'forumdata/errorlog.php', 'forumdata/ratelog.php', 'forumdata/cplog.php', 'forumdata/modslog.php', 'forumdata/illegallog.php' ); foreach(array('templates', 'forumdata/logs', 'forumdata/cache', 'forumdata/templates') as $directory) { getdirentry($directory); } $fault = 0; foreach($entryarray as $entry) { $fullentry = './'.$entry; if(!is_dir($fullentry) && !file_exists($fullentry)) { continue; } else { if(!is_writeable($fullentry)) { $dir_perm .= "\n\t\t".(is_dir($fullentry) ? '目录' : '文件')." ./$entry {$error_style_s}无法写入.{$style_e}"; $msg .= "\n\t\t".(is_dir($fullentry) ? '目录' : '文件')." ./$entry {$error_style_s}无法写入.{$style_e}"; $fault = 1; } } } $dir_perm .= $fault ? '' : $ok_style_s.'文件及目录属性全部正确'.$style_e; /** * gd库所需函数的检查 */ $gd_check = ''; if(!extension_loaded('gd')) { $gd_check .= '您的php.ini未开启extension=php_gd2.dll(windows)或者未编译gd库(linux).'; } elseif(!function_exists('gd_info') && phpversion() < '4.3') { $gd_check .= 'php版本低于4.3.0,不支持高版本的gd库,请升级您的php版本.'; } else { $ver_info = gd_info(); preg_match('/([0-9\.]+)/', $ver_info['GD Version'], $match); if($match[0] < '2.0') { $gd_check .= "\n\t\tgd版本低于2.0,请升级您的gd版本以支持gd的验证码和水印."; } elseif(!(function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) ) { $gd_check .= "\n\t\tgd版本不支持jpeg的验证码和水印."; } elseif(!(function_exists('imagecreatefromgif') && function_exists('imagegif')) ) { $gd_check .= "\n\t\tgd版本不支持gif的验证码和水印."; } elseif(!(function_exists('imagecreatefrompng') && function_exists('imagepng')) ) { $gd_check .= "\n\t\tgd版本不支持png的验证码和水印."; } else { $gd_check .= '正常开启'; } } if($gd_check != '正常开启') { $gd_check = $error_style_s.$gd_check.$style_e; } else { $gd_check = $ok_style_s.$gd_check.$style_e; } /** * 检查ming库,目的为检查是否支持flash验证码 */ $ming_check = ''; if(extension_loaded('ming')) { if(substr($curr_os,0,3) == 'WIN') { $ming_check .= '您的php.ini未开启extension=php_ming.dll,所以无法支持flash验证码'; } else { $ming_check .= '您未编译ming库,所以无法支持flash验证码'; } } else { $ming_check .= '您的系统支持flash验证码,如果还无法使用flash验证码的话,有可能是您的php版本太低'; } /** *检查系统是否可以执行ImageMagick的命令 */ $imagemagick_check = ''; if(!function_exists('exec')) { $imagemagick_check .='您的php.ini里或者空间商禁止了使用exec函数,无法使用ImageMagick'; } else { $imagemagick_check .='您现在只需安装好ImageMagick,然后配置好相关参数就可以使用ImageMagick(使用之前请先使用后台的预览功能来检查您的ImageMagick是否安装好)'; } if($msg == '') { $msg = "{$ok_style_s}没有发现系统环境问题.{$style_e}"; } else { $msg = $error_style_s.$msg.$style_e; } $doctor_env = " 操作系统--->$curr_os WEB 引擎 --->$curr_server_software PHP 版本--->$curr_php_version MySQL 版本--->$curr_mysql Zend 版本--->".OPTIMIZER_VERSION." 程序最长运行时间(max_execution_time)--->{$max_execution_time}秒 内存大小(memory_limit)--->$memory_limit 是否允许打开远程文件(allow_url_fopen)--->$allow_url_fopen 是否允许使用短标记(short_open_tag)--->$curr_short_tag 安全模式(safe_mode)--->$curr_safe_mode 错误提示(display_errors)--->$curr_display_errors XML 解析器--->$curr_xml authkey 是否存在--->$authkeyexist 系统临时目录--->$tmpwritable 磁盘空间--->$curr_disk_space 附件上传--->$curr_upload_status 函数 file()--->$funcexistfile 函数 fopen()--->$funcexistfopen 目录权限---$dir_perm GD 库--->$gd_check ming 库--->$ming_check ImageMagick --->$imagemagick_check 系统环境错误提示\r\n\t$msg"; } if(!$doctor_step) { $doctor_step = '0'; @unlink('./forumdata/doctor_cache.cache'); } //php错误检查 $dberrnomsg = array ( '1008' => '数据库不存在,删除数据库失败', '1016' => '无法打开数据文件', '1041' => '系统内存不足', '1045' => '连接数据库失败,用户名或密码错误', '1046' => '选择数据库失败,请正确配置数据库名称', '1044' => '当前用户没有访问数据库的权限', '1048' => '字段不能为空', '1049' => '数据库不存在', '1051' => '数据表不存在', '1054' => '字段不存在', '1062' => '字段值重复,入库失败',//不中断 '1064' => '可能原因:1.数据超长或类型不匹配;2.数据库记录重复',//不中断 '1065' => '无效的SQL语句,SQL语句为空',//不中断 '1081' => '不能建立Socket连接', '1129' => '数据库出现异常,请重启数据库', '1130' => '连接数据库失败,没有连接数据库的权限', '1133' => '数据库用户不存在', '1141' => '当前用户无权访问数据库', '1142' => '当前用户无权访问数据表', '1143' => '当前用户无权访问数据表中的字段', '1146' => '数据表不存在', '1149' => 'SQL语句语法错误', '1169' => '字段值重复,更新记录失败',//不中断 '2003' => '请检查数据库服务器端口设置是否正确,默认端口为 3306', '2005' => '数据库服务器不存在', '1114' => 'Forum onlines reached the upper limit', ); $display_errorall = ''; $tempdir = $phpfile_array[$doctor_step]; $dirname = $dir_array[$doctor_step]; //foreach($phpfile_array as $tempdir=>$dirname) { $display_error = ''; $mtime = explode(' ', microtime()); $time_start = $mtime[1] + $mtime[0]; if(!in_array($tempdir, array('templates', 'cache', 'discuzroot'))) exit('参数错误'); $tempdir == 'discuzroot' ? $dir = './' : $dir = 'forumdata/'.$tempdir.'/'; create_checkfile(); if (is_dir($dir)) { if ($dh = dir($dir)) { $PHP_SELF = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $BASESCRIPT = basename($PHP_SELF); $host = htmlspecialchars($_SERVER['HTTP_HOST']); $boardurl = preg_replace("/\/+(api|archiver|wap)?\/*$/i", '', substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'))).'/'; while (($file = $dh->read()) !== false) { if ($file != '.' && $file != '..' && $file != 'index.htm' && $file != 'checkfile.php' && $file != 'tools.php' && !is_dir($file)) { $extnum = strrpos($file, '.') + 1; $exts = strtolower(substr($file, $extnum)); if($exts == 'php') { $content = ''; if($dir == './') { $content = http_fopen($host, "{$boardurl}{$file}"); } else { $content = http_fopen($host, "{$boardurl}/forumdata/checkfile.php?file=$file"); } $content = str_replace(': Call to undefined function: ','',$content); $content = str_replace(': Call to undefined function ','',$content); $out = $out_mysql = array(); if(preg_match_all("/.+<\/b>:.* on line \d+<\/b>/",$content,$out) || preg_match_all("/Error<\/b>:.+
\nErrno.<\/b>:\s{2}([1-9][0-9]+)/",$content,$out_mysql)) { $display_error .= "\t{$error_style_s}$file ---错误:{$style_e}"; foreach ($out[0] as $value) { $display_error .= "\n\t\t".$value."\n"; } foreach ($out_mysql[0] as $key =>$value) { $display_error .= "\n\t\t{$error_style_s}".$dberrnomsg[$out_mysql[1][$key]].$style_e; $display_error .= "\n\t\t".str_replace("\n", '', $value); } } } } } $dh->close(); } else { echo "$dir目录不存在或不可读取."; } } @unlink('./forumdata/checkfile.php'); if($display_error == '') { $dot = '缓存文件'; $dir == './' && $dot = 'php文件'; $display_errorall .= "\n---------{$ok_style_s}{$dirname}{$style_e}下没有检测到有错误的$dot.\n"; } else { $display_errorall .= "\n---------{$error_style_s}{$dirname}{$style_e}\n".$display_error; } $fp = @fopen('./forumdata/doctor_cache.cache', 'ab'); @fwrite($fp, $display_errorall); @fclose($fp); if($doctor_step < $doctor_top) { $doctor_step ++; continue_redirect('dz_doctor', "&doctor_step=$doctor_step"); htmlfooter(); } $fp = @fopen('./forumdata/doctor_cache.cache','rb'); $display_errorall = @fread($fp, @filesize('./forumdata/doctor_cache.cache')); @fclose($fp); @unlink('./forumdata/doctor_cache.cache'); //} $display_errorall = str_replace('', '', $display_errorall); $display_errorall = str_replace('', '', $display_errorall); $display_errorall = str_replace('
', '', $display_errorall); $records_style = "\n\n==={$title_style_s}配置文件检查{$title_style_e}=================================================$doctor_config\n==={$title_style_s}系统环境检查{$title_style_e}=================================================\n$doctor_env\n==={$title_style_s}文件错误检查{$title_style_e}=================================================\n$display_errorall\n==={$title_style_s}检查完毕{$title_style_e}====================================================="; $search_style_all = array($error_style_s, $style_e, $ok_style_s, $title_style_s, $title_style_e); $replace_style_all = array('', '', '', '', ''); $records = str_replace($search_style_all, '', $records_style); echo "

论坛医生诊断结果






"; htmlfooter(); } elseif ($action == 'dz_filecheck') {//搜索未知文件 //搜索未知文件功能 if(!file_exists("./config.inc.php") && !file_exists("config.php")) { htmlheader(); cexit("

请先上传config文件以保证您的数据库能正常链接!

"); } $do = isset($_GET['do']) ? $_GET['do'] : 'advance'; $lang = array( 'filecheck_fullcheck' => '搜索未知文件', 'filecheck_fullcheck_select' => '搜索未知文件 - 选择需要搜索的目录', 'filecheck_fullcheck_selectall' => '[搜索全部目录]', 'filecheck_fullcheck_start' => '开始时间:', 'filecheck_fullcheck_current' => '当前时间:', 'filecheck_fullcheck_end' => '结束时间:', 'filecheck_fullcheck_file' => '当前文件:', 'filecheck_fullcheck_foundfile' => '发现未知文件数: ', 'filecheck_fullcheck_nofound' => '没有发现任何未知文件' ); if(!$discuzfiles = @file('./admin/discuzfiles.md5')) { show_tools_message('没有找到文件的MD5值'); } htmlheader(); if($do == 'advance') { $dirlist = array(); $starttime = date('Y-m-d H:i:s'); $cachelist = $templatelist = array(); if(empty($checkdir)) { checkdirs('./'); } elseif($checkdir == 'all') { echo "\n"; } else { $checkdir = str_replace('..', '', $checkdir); $checkdir = $checkdir{0} == '/' ? '.'.$checkdir : $checkdir; checkdirs($checkdir.'/'); echo "\n"; } echo '

搜索未知文件

'; if(empty($checkdir)) { echo '
'.(empty($checkdir) ? ''.$lang['filecheck_fullcheck_selectall'].'' : $lang['filecheck_fullcheck'].($checkdir != 'all' ? ' - '.$checkdir : '')).'

    '; foreach($dirlist as $dir) { $subcount = count(explode('/', $dir)); echo '
  • '.str_repeat('-', ($subcount - 2) * 4); echo ''.basename($dir).'
  • '; } echo '

'; } else { echo ''.$lang['filecheck_fullcheck_start'].' '.$starttime.'



'; echo ""; } htmlfooter(); } elseif($do == 'advancenext') { $nopass = 0; foreach($discuzfiles as $line) { $md5files[] = trim(substr($line, 34)); } $foundfile = checkfullfiles($dir); echo ""; exit; } } elseif ($action == 'dz_mysqlclear') {//数据库清理 ob_implicit_flush(); define('IN_DISCUZ', TRUE); if(@!include("./config.inc.php")) { if(@!include("./config.php")) { htmlheader(); cexit("

请先上传config文件以保证您的数据库能正常链接!

"); } } require './include/db_'.$database.'.class.php'; $db = new dbstuff; $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect); $db->select_db($dbname); if(!get_cfg_var('register_globals')) { @extract($_GET, EXTR_SKIP); } $rpp = "1000"; //每次处理多少条数据 $totalrows = isset($totalrows) ? $totalrows : 0; $convertedrows = isset($convertedrows) ? $convertedrows : 0; $start = isset($start) && $start > 0 ? $start : 0; $sqlstart = isset($start) && $start > $convertedrows ? $start - $convertedrows : 0; $end = $start + $rpp - 1; $stay = isset($stay) ? $stay : 0; $converted = 0; $step = isset($step) ? $step : 0; $info = isset($info) ? $info : ''; $action = array( '1'=>'冗余回复数据清理', '2'=>'冗余附件数据清理', '3'=>'冗余会员数据清理', '4'=>'冗余板块数据清理', '5'=>'主题信息清理', '6'=>'完成数据冗余清理' ); $steps = count($action); $actionnow = isset($action[$step]) ? $action[$step] : '结束'; $maxid = isset($maxid) ? $maxid : 0; $tableid = isset($tableid) ? $tableid : 1; htmlheader(); if($step==0){ ?>

数据库冗余数据清理

清理项目详细信息
Posts表的清理[单步清理]
Attachments表的清理[单步清理]
Members表的清理[单步清理]
Forums表的清理[单步清理]
Threads表的清理[单步清理]
所有表的清理[全部清理]
= $start AND pid <= $end"; $posts=$db->query($query); while ($post = $db->fetch_array($posts)){ $query = $db->query("SELECT tid FROM {$tablepre}threads WHERE tid='".$post['tid']."'"); if ($db->result($query, 0)) { } else { $convertedrows ++; $db->query("DELETE FROM {$tablepre}posts WHERE pid='".$post['pid']."'"); } $converted = 1; $totalrows ++; } if($converted || $end < $maxid) { continue_redirect(); } else { stay_redirect(); } } elseif ($step == '2'){ if($start == 0) { validid('aid','attachments'); } $query = "SELECT aid,pid,attachment FROM {$tablepre}attachments WHERE aid >= $start AND aid <= $end"; $posts=$db->query($query); while ($post = $db->fetch_array($posts)){ $query = $db->query("SELECT pid FROM {$tablepre}posts WHERE pid='".$post['pid']."'"); if ($db->result($query, 0)) { } else { $convertedrows ++; $db->query("DELETE FROM {$tablepre}attachments WHERE aid='".$post['aid']."'"); $attachmentdir = TOOLS_ROOT.'./attachments/'; @unlink($attachmentdir.$post['attachment']); } $converted = 1; $totalrows ++; } if($converted || $end < $maxid) { continue_redirect(); } else { stay_redirect(); } } elseif ($step == '3'){ if($start == 0) { validid('uid','memberfields'); } $query = "SELECT uid FROM {$tablepre}memberfields WHERE uid >= $start AND uid <= $end"; $posts=$db->query($query); while ($post = $db->fetch_array($posts)){ $query = $db->query("SELECT uid FROM {$tablepre}members WHERE uid='".$post['uid']."'"); if ($db->result($query, 0)) { } else { $convertedrows ++; $db->query("DELETE FROM {$tablepre}memberfields WHERE uid='".$post['uid']."'"); } $converted = 1; $totalrows ++; } if($converted || $end < $maxid) { continue_redirect(); } else { stay_redirect(); } } elseif ($step == '4'){ if($start == 0) { validid('fid','forumfields'); } $query = "SELECT fid FROM {$tablepre}forumfields WHERE fid >= $start AND fid <= $end"; $posts=$db->query($query); while ($post = $db->fetch_array($posts)){ $query = $db->query("SELECT fid FROM {$tablepre}forums WHERE fid='".$post['fid']."'"); if ($db->result($query, 0)) { } else { $convertedrows ++; $db->query("DELETE FROM {$tablepre}forumfields WHERE fid='".$post['fid']."'"); } $converted = 1; $totalrows ++; } if($converted || $end < $maxid) { continue_redirect(); } else { stay_redirect(); } } elseif ($step == '5'){ if($start == 0) { validid('tid','threads'); } $query = "SELECT tid, subject FROM {$tablepre}threads WHERE tid >= $start AND tid <= $end"; $posts=$db->query($query); while ($threads = $db->fetch_array($posts)){ $query = $db->query("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0'"); $replynum = $db->result($query, 0) - 1; if ($replynum < 0) { $db->query("DELETE FROM {$tablepre}threads WHERE tid='".$threads['tid']."'"); } else { $query = $db->query("SELECT a.aid FROM {$tablepre}posts p, {$tablepre}attachments a WHERE a.tid='".$threads['tid']."' AND a.pid=p.pid AND p.invisible='0' LIMIT 1"); $attachment = $db->num_rows($query) ? 1 : 0;//修复附件 $query = $db->query("SELECT pid, subject, rate FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0' ORDER BY dateline LIMIT 1"); $firstpost = $db->fetch_array($query); $firstpost['subject'] = trim($firstpost['subject']) ? $firstpost['subject'] : $threads['subject']; //针对某些转换过来的论坛的处理 $firstpost['subject'] = addslashes($firstpost['subject']); @$firstpost['rate'] = $firstpost['rate'] / abs($firstpost['rate']);//修复发帖 $query = $db->query("SELECT author, dateline FROM {$tablepre}posts WHERE tid='".$threads['tid']."' AND invisible='0' ORDER BY dateline DESC LIMIT 1"); $lastpost = $db->fetch_array($query);//修复最后发帖 $db->query("UPDATE {$tablepre}threads SET subject='".$firstpost['subject']."', replies='$replynum', lastpost='".$lastpost['dateline']."', lastposter='".addslashes($lastpost['author'])."', rate='".$firstpost['rate']."', attachment='$attachment' WHERE tid='".$threads['tid']."'", 'UNBUFFERED'); $db->query("UPDATE {$tablepre}posts SET first='1', subject='".$firstpost['subject']."' WHERE pid='".$firstpost['pid']."'", 'UNBUFFERED'); $db->query("UPDATE {$tablepre}posts SET first='0' WHERE tid='".$threads['tid']."' AND pid<>'".$firstpost['pid']."'", 'UNBUFFERED'); $convertedrows ++; } $converted = 1; $totalrows ++; } if($converted || $end < $maxid) { continue_redirect(); } else { stay_redirect(); } } elseif ($step=='6'){ echo '

数据库冗余数据清理

完成冗余数据清理

所有数据清理操作完毕. 共处理'.$allconvertedrows.'条数据.

'; } htmlfooter(); } elseif ($action == 'dz_repair_auto') {//修复自增长ID //初始化数据库连接帐号 getdbcfg(); mysql_connect($dbhost, $dbuser, $dbpw); mysql_select_db($dbname); @set_time_limit(0); htmlheader(); echo '

Discuz! 自增长字段修复

'; $querysql = array( 'activityapplies' => 'applyid', 'adminnotes' => 'id', 'advertisements' => 'advid', 'announcements' => 'id', 'attachments' => 'aid', 'attachtypes' => 'id', 'banned' => 'id', 'bbcodes' => 'id', 'crons' => 'cronid', 'faqs' => 'id', 'forumlinks' => 'id', 'forums' => 'fid', 'itempool' => 'id', 'magicmarket' => 'mid', 'magics' => 'magicid', 'medals' => 'medalid', 'members' => 'uid', 'pluginhooks' => 'pluginhookid', 'plugins' => 'pluginid', 'pluginvars' => 'pluginvarid', 'pms' => 'pmid', 'pmsearchindex' => 'searchid', 'polloptions' => 'polloptionid', 'posts' => 'pid', 'profilefields' => 'fieldid', 'projects' => 'id', 'ranks' => 'rankid', 'searchindex' => 'searchid', 'smilies' => 'id', 'styles' => 'styleid', 'stylevars' => 'stylevarid', 'templates' => 'templateid', 'threads' => 'tid', 'threadtypes' => 'typeid', 'words' => 'id' ); $sqladd = array( 'imagetypes' => 'typeid', 'tradecomments' => 'id', 'typemodels' => 'id', 'typeoptions' => 'optionid' ); define('IN_DISCUZ', TRUE); if(@include TOOLS_ROOT.'./discuz_version.php') { if(substr(DISCUZ_VERSION, 0, 1) == 6) { $querysql = array_merge($querysql, $sqladd); }else if(substr(DISCUZ_VERSION, 0, 3) != '5.5') { errorpage("

很抱歉,该功能目前只支持Discuz!5.5版本和Discuz!6.0版本。

",'',0); } }else { errorpage("./discuz_version.php文件不存在,请确定该文件的存在。",'',0); } echo '
检查结果
'; foreach($querysql as $key => $keyfield) { $tablestate = '正常'; echo ''; if($query = @mysql_query("Describe $tablepre$key $keyfield")) { if(@mysql_num_rows($query) > 0) { $field = @mysql_fetch_array($query); if($field[3] != 'PRI') { @mysql_query("ALTER TABLE $tablepre$key ADD PRIMARY KEY ($keyfield)"); $tablestate = '已经修复'; } if(empty($field[5])) { mysql_query("ALTER TABLE $tablepre$key CHANGE $keyfield $keyfield $field[1] NOT NULL AUTO_INCREMENT"); $tablestate = '已经修复'; } } else { $tablestate = '字段不存在'; } } else { $tablestate = '表不存在'; } echo ''; } echo '
数据表名字段名自增长状态
'.$tablepre.$key.''.$keyfield.''.$tablestate.'
'; specialdiv(); echo '
'; htmlfooter(); } elseif ($action == 'dz_replace') {//内容替换 htmlheader(); $rpp = "500"; //每次处理多少条数据 $totalrows = isset($totalrows) ? $totalrows : 0; $convertedrows = isset($convertedrows) ? $convertedrows : 0; $start = isset($start) && $start > 0 ? $start : 0; $end = $start + $rpp - 1; $converted = 0; $maxid = isset($maxid) ? $maxid : 0; $threads_mod = isset($threads_mod) ? $threads_mod : 0; $threads_banned = isset($threads_banned) ? $threads_banned : 0; $posts_mod = isset($posts_mod) ? $posts_mod : 0; if($stop == 1) { echo "

帖子内容批量替换

"; $threads_banned > 0 && print(""); $threads_mod > 0 && print(""); $posts_mod > 0 && print(""); echo ""; echo ""; echo "
暂停替换

  • ".$threads_banned."个主题被放入回收站.


  • ".$threads_mod."个主题被放入审核列表.


  • ".$posts_mod."个回复被放入审核列表.


  • 替换了".$convertedrows."个帖子



  • 继续

    "; htmlfooter(); } ob_implicit_flush(); define('IN_DISCUZ', TRUE); if(@!include("./config.inc.php")) { if(@!include("./config.php")) { cexit("

    请先上传config文件以保证您的数据库能正常链接!

    "); } } require './include/db_'.$database.'.class.php'; $db = new dbstuff; $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect); $db->select_db($dbname); $selectwords_cache = './forumdata/cache/selectwords_cache.php'; if(isset($replacesubmit) || $start > 0) { if($maxid ==0) { validid('pid','posts'); } if(!file_exists($selectwords_cache) || is_array($selectwords)){ if(count($selectwords) < 1) { echo "

    帖子内容批量替换

    提示信息
    您还没有选择要过滤的词语.   [返回]
    "; htmlfooter(); } else { $fp = @fopen($selectwords_cache,w); $content = ""; if(!@fwrite($fp,$content)) { echo "写入缓存文件$selectwords_cache 错误,请确认路径是否可写.   [返回]"; htmlfooter(); } else { require_once "$selectwords_cache"; } @fclose($fp); } } else { require_once "$selectwords_cache"; } $array_find = $array_replace = $array_findmod = $array_findbanned = array(); $query = $db->query("SELECT find,replacement from {$tablepre}words where id in($selectwords)");//获得现有规则{BANNED}放回收站 {MOD}放进审核列表 while($row = $db->fetch_array($query)) { $find = preg_quote($row['find'], '/'); $replacement = $row['replacement']; if($replacement == '{BANNED}') { $array_findbanned[] = $find; } elseif($replacement == '{MOD}') { $array_findmod[] = $find; } else { $array_find[] = $find; $array_replace[] = $replacement; } } function topattern_array($source_array) { //将数组正则化 $source_array = preg_replace("/\{(\d+)\}/",".{0,\\1}",$source_array); foreach($source_array as $key => $value) { $source_array[$key] = '/'.$value.'/i'; } return $source_array; } $array_find = topattern_array($array_find); $array_findmod = topattern_array($array_findmod); $array_findbanned = topattern_array($array_findbanned); //查询posts表准备替换 $sql = "SELECT pid, tid, first, subject, message from {$tablepre}posts where pid >= $start and pid <= $end"; $query = $db->query($sql); while($row = $db->fetch_array($query)) { $pid = $row['pid']; $tid = $row['tid']; $subject = $row['subject']; $message = $row['message']; $first = $row['first']; $displayorder = 0;// -2审核 -1回收站 if(count($array_findmod) > 0) { foreach($array_findmod as $value){ if(preg_match($value,$subject.$message)){ $displayorder = '-2'; break; } } } if(count($array_findbanned) > 0) { foreach($array_findbanned as $value){ if(preg_match($value,$subject.$message)){ $displayorder = '-1'; break; } } } if($displayorder < 0) { if($displayorder == '-2' && $first == 0) {//如成立就移到审核回复 $posts_mod ++; $db->query("UPDATE {$tablepre}posts SET invisible = '$displayorder' WHERE pid = $pid"); } else { if($db->affected_rows($db->query("UPDATE {$tablepre}threads SET displayorder = '$displayorder' WHERE tid = $tid and displayorder >= 0")) > 0) { $displayorder == '-2' && $threads_mod ++; $displayorder == '-1' && $threads_banned ++; } } } $subject = preg_replace($array_find,$array_replace,addslashes($subject)); $message = preg_replace($array_find,$array_replace,addslashes($message)); if($subject != addslashes($row['subject']) || $message != addslashes($row['message'])) { if($db->query("UPDATE {$tablepre}posts SET subject = '$subject', message = '$message' WHERE pid = $pid")) { $convertedrows ++; } } $converted = 1; } if($converted || $end < $maxid) { continue_redirect('dz_replace',"&replacesubmit=1&threads_banned=$threads_banned&threads_mod=$threads_mod&posts_mod=$posts_mod"); } else { echo "

    帖子内容批量替换

    "; $threads_banned > 0 && print(""); $threads_mod > 0 && print(""); $posts_mod > 0 && print(""); echo ""; echo "
    批量替换完毕

  • ".$threads_banned."个主题被放入回收站.


  • ".$threads_mod."个主题被放入审核列表.


  • ".$posts_mod."个回复被放入审核列表.


  • 替换了".$convertedrows."个帖子


  • "; @unlink($selectwords_cache); } } else { if($db->version > '4.1'){ $serverset = 'character_set_connection=gbk, character_set_results=gbk, character_set_client=binary'; $serverset && $db->query("SET $serverset"); } $query = $db->query("select * from {$tablepre}words"); $i = 1; if($db->num_rows($query) < 1) { echo "

    帖子内容批量替换

    提示信息

    对不起,现在还没有过滤规则,请进入论坛后台设置.

    "; htmlfooter(); } ?>

    批量替换帖子内容

    fetch_array($query)) { ?>
    序号 不良词语 替换为
         
    注意:
    • 本程序会按照论坛现有过滤规则操作所有帖子内容.如需修改请进论坛后台
    • 上表列出了您论坛当前的过滤词语.


    read()) !== false) { if ($file != "." && $file != ".." && $file != "index.htm" && !is_dir($file)) { unlink('./forumdata/'.$dir.'/'.$file); } } } else { $clearmsg .= './forumdata/'.$dir.'清除失败.
    '; } } htmlheader(); echo '

    更新缓存

    提示信息
    '; if($clearmsg == '') $clearmsg = '更新缓存完毕.'; echo $clearmsg.'
    '; htmlfooter(); } elseif ($action == 'all_setadmin') {//重置管理员帐号密码, if($whereis == 'is_dz') { $sql_findadmin = "SELECT * FROM {$tablepre}members WHERE adminid=1"; $sql_select = "SELECT uid FROM {$tablepre}members WHERE $_POST[loginfield] = '$_POST[where]'"; //$sql_update = "UPDATE {$tablepre}members SET adminid='1', groupid='1' WHERE $_POST[loginfield] = '$_POST[where]' limit 1"; $username = 'username'; $uid = 'uid'; $secq = 1; if(UC_CONNECT == 'mysql') {//判断连接ucenter的方式,如果是mysql方式,可以修改密码,否则提示去uc后台修改密码 $rspw = 1; } else { $rspw = 0; } } elseif($whereis == 'is_uc') { $secq = 0; $rspw = 1; } elseif($whereis == 'is_ec') { $sql_findadmin = "SELECT * FROM {$tablepre}admin_user"; $sql_select = "SELECT user_id FROM {$tablepre}admin_user WHERE $_POST[loginfield] = '$_POST[where]'"; $sql_update = ""; $sql_rspw = "UPDATE {$tablepre}admin_user SET password='".md5($_POST['password'])."' WHERE $_POST[loginfield] = '$_POST[where]' limit 1"; $username = 'user_name'; $uid = 'user_id'; $secq = 0; $rspw = 1; } elseif($whereis == 'is_uch') { $sql_findadmin = "SELECT * FROM {$tablepre}space WHERE groupid = 1"; $sql_select = "SELECT uid FROM {$tablepre}space WHERE $_POST[loginfield] = '$_POST[where]'"; $sql_update = "UPDATE {$tablepre}space SET groupid='1' WHERE $_POST[loginfield] = '$_POST[where]'"; $username = 'username'; $uid = 'uid'; $secq = 0; if(UC_CONNECT == 'mysql') { $rspw = 1; } else { $rspw = 0; } } $info = ""; $info_uc = ""; htmlheader(); ?>

    找回管理员

    '4.1'){ $serverset = 'character_set_connection=gbk, character_set_results=gbk, character_set_client=binary'; $serverset .=$my_version > '5.0.1' ? ((empty($serverset))? '' : ',').'sql_mode=\'\'' : ''; $serverset && mysql_query("SET $serverset"); } //查询已经存在的管理员 if($whereis != 'is_uc') { $findadmin_query = mysql_query($sql_findadmin); $admins = ''; while($findadmins = mysql_fetch_array($findadmin_query)) { $admins .= ' '.$findadmins[$username]; } } if(!empty($_POST['loginsubmit'])) { if($whereis == 'is_uc') { define(ROOT_DIR,dirname(__FILE__)."/"); $configfile = ROOT_DIR."./data/config.inc.php"; $uc_password = $_POST["password"]; $salt = substr(uniqid(rand()), 0, 6); if(!$uc_password){ $info = "密码不能为空"; }else{ $md5_uc_password = md5(md5($uc_password).$salt); $config = file_get_contents($configfile); $config = preg_replace("/define\('UC_FOUNDERSALT',\s*'.*?'\);/i", "define('UC_FOUNDERSALT', '$salt');", $config); $config = preg_replace("/define\('UC_FOUNDERPW',\s*'.*?'\);/i", "define('UC_FOUNDERPW', '$md5_uc_password');", $config); $fp = @fopen($configfile, 'w'); @fwrite($fp, $config); @fclose($fp); $info = "UCenter创始人密码更改成功为:$uc_password"; } }else { if(@mysql_num_rows(mysql_query($sql_select)) < 1) { if($whereis == 'is_ec') { $info = '无此管理员用户!请检查用户名是否正确。重新输入 管理员帐号.

    '; } else { $info = '无此用户!请检查用户名是否正确。重新输入 或者重新注册.

    '; } } else { if($whereis == 'is_dz') { $sql_update1 = "UPDATE {$tablepre}members SET adminid='1', groupid='1' WHERE $_POST[loginfield] = '$_POST[where]' limit 1"; $sql_update2 = "UPDATE {$tablepre}members SET adminid='1', groupid='1',secques='' WHERE $_POST[loginfield] = '$_POST[where]' limit 1"; $sql_update = $_POST['issecques'] ? $sql_update2 : $sql_update1; } if(mysql_query($sql_update)) { $_POST[loginfield] = $_POST[loginfield] == $username ? '用户名' : 'UID号码'; $info = "已将$_POST[loginfield]为 $_POST[where] 的用户设置成管理员。

    "; } if($rspw) { if($whereis == 'is_ec') { if(mysql_query($sql_rspw)) { $mysql_affected_rows = mysql_affected_rows(); $_POST[loginfield] = $_POST[loginfield] == $username ? '用户名' : 'UID号码'; $info .= "已将$_POST[loginfield]为 $_POST[where] 的管理员密码设置为:$_POST[password]

    "; } else { $info = '失败请检查Mysql设置config.inc.php'; } } elseif($whereis == 'is_dz') { //如果是dz,首先要连接到uc里面然后执行$sql_rspw修改密码 $salt = substr(md5(time()), 0, 6); $psw = md5(md5($_POST['password']).$salt); mysql_connect(UC_DBHOST, UC_DBUSER, UC_DBPW); $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."' WHERE username = '$_POST[where]' limit 1"; mysql_query($sql_rspw); $info .= "已将$_POST[loginfield]为 $_POST[where] 的管理员密码设置为:$_POST[password]

    "; } elseif($whereis == 'is_uch') { $salt = substr(md5(time()), 0, 6); $psw = md5(md5($_POST['password']).$salt); mysql_connect(UC_DBHOST, UC_DBUSER, UC_DBPW); $sql_rspw = "UPDATE ".UC_DBTABLEPRE."members SET password='".$psw."',salt='".$salt."' WHERE username = '$_POST[where]' limit 1"; mysql_query($sql_rspw); $info .="已将$_POST[loginfield]为 $_POST[where] 的管理员密码设置为:$_POST[password]

    "; } } else { $info_rspw = "管理员密码请登录UC后台去改。 点击进入UC后台"; } } } errorpage($info,'重置管理员帐号',0,0); } else { ?>
    已存在管理员列表
    用户名UID
    请输入密码
    密码修改提示 管理员密码请登录UC后台去改。点击进入UC后台
    是否清除安全提问 是        
    '; errorpage("
    成功关闭工具箱!强烈建议您在不需要本程序的时候及时进行删除
    ",'锁定工具箱'); } else { errorpage('注意您的目录没有写入权限,我们无法给您提供安全保障,请删除论坛根目录下的tool.php文件!','锁定工具箱'); } } elseif ($action == 'dz_moveattach') {//移动附件存放方式 //初始化数据库连接帐号 getdbcfg(); //连接数据库 define('IN_DISCUZ', TRUE); require_once TOOLS_ROOT."./config.inc.php"; require_once TOOLS_ROOT."./include/db_mysql.class.php"; $db = new dbstuff; $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset); $dbuser = $dbpw = $dbname = $pconnect = NULL; htmlheader(); echo "

    附件保存方式

    "; $atoption = array( '0' => '标准(全部存入同一目录)', '1' => '按论坛存入不同目录', '2' => '按文件类型存入不同目录', '3' => '按月份存入不同目录', '4' => '按天存入不同目录', ); if (!empty($_POST['moveattsubmit']) || $step == 1) { $rpp = "500"; //每次处理多少条数据 $totalrows = isset($totalrows) ? $totalrows : 0; $convertedrows = isset($convertedrows) ? $convertedrows : 0; $start = isset($start) && $start > 0 ? $start : 0; $end = $start + $rpp - 1; $converted = 0; $maxid = isset($maxid) ? $maxid : 0; $newattachsave = isset($newattachsave) ? $newattachsave : 0; $step = 1; if ($start <= 1) { $db->query("UPDATE {$tablepre}settings SET value = '$newattachsave' WHERE variable = 'attachsave'"); $cattachdir = $db->result($db->query("SELECT value FROM {$tablepre}settings WHERE variable = 'attachdir'"), 0); validid('aid', 'attachments'); } $attachpath = isset($cattachdir) ? TOOLS_ROOT.$cattachdir : TOOLS_ROOT.'./attachments'; $query = $db->query("SELECT aid, tid, dateline, filename, filetype, attachment FROM {$tablepre}attachments WHERE aid >= $start AND aid <= $end"); while ($a = $db->fetch_array($query)) { $aid = $a['aid']; $tid = $a['tid']; $dateline = $a['dateline']; $filename = $a['filename']; $filetype = $a['filetype']; $attachment = $a['attachment']; $oldpath = $attachpath.'/'.$attachment; if (file_exists($oldpath)) { $realname = substr(strrchr('/'.$attachment, '/'), 1); if ($newattachsave == 1) { $fid = $db->result($db->query("SELECT fid FROM {$tablepre}threads WHERE tid = '$tid' LIMIT 1"), 0); $fid = $fid ? $fid : 0; } elseif ($newattachsave == 2) { $extension = strtolower(fileext($filename)); } if ($newattachsave) { switch($newattachsave) { case 1: $attach_subdir = 'forumid_'.$fid; break; case 2: $attach_subdir = 'ext_'.$extension; break; case 3: $attach_subdir = 'month_'.gmdate('ym', $dateline); break; case 4: $attach_subdir = 'day_'.gmdate('ymd', $dateline); break; } $attach_dir = $attachpath.'/'.$attach_subdir; if(!is_dir($attach_dir)) { mkdir($attach_dir, 0777); @fclose(fopen($attach_dir.'/index.htm', 'w')); } $newattachment = $attach_subdir.'/'.$realname; } else { $newattachment = $realname; } $newpath = $attachpath.'/'.$newattachment; $asql1 = "UPDATE {$tablepre}attachments SET attachment = '$newattachment' WHERE aid = '$aid'"; $asql2 = "UPDATE {$tablepre}attachments SET attachment = '$attachment' WHERE aid = '$aid'"; if ($db->query($asql1)) { if (rename($oldpath, $newpath)) { $convertedrows ++; } else { $db->query($asql2); } } $totalrows ++; } } if($converted || $end < $maxid) { continue_redirect('moveattach', '&newattachsave='.$newattachsave.'&cattachdir='.$cattachdir); } else { $msg = "$atoption[$newattachsave] 移动附件完毕
  • 共有".$totalrows."个附件数据

  • 移动了".$convertedrows."个附件
  • "; errorpage($msg,'',0,0); } } else { $attachsave = $db->result($db->query("SELECT value FROM {$tablepre}settings WHERE variable = 'attachsave' LIMIT 1"), 0); $checked[$attachsave] = 'checked'; echo "
    本设置将重新规范所有附件的存放方式。注意:为防止发生意外,请注意备份数据库和附件。
    "; foreach($atoption as $key => $val){ echo "
  •   $val

  • "; } echo "
    "; specialdiv(); } htmlfooter(); }elseif($action == 'dz_rplastpost'){//修复版块的最后回复 //初始化数据库连接帐号 getdbcfg(); //连接数据库 define('IN_DISCUZ', TRUE); require_once TOOLS_ROOT."./config.inc.php"; require_once TOOLS_ROOT."./include/db_mysql.class.php"; $db = new dbstuff; $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset); $dbuser = $dbpw = $dbname = $pconnect = NULL; if($db->version > '4.1'){ $serverset = 'character_set_connection=gbk, character_set_results=gbk, character_set_client=binary'; $serverset && $db->query("SET $serverset"); } $selectfid = $_POST['fid']; if($selectfid) { $i = 0; foreach($selectfid as $fid) {//存在要更新的FID 执行更新 $sql = "select t.tid, t.subject, p.subject AS psubject, p.dateline, p.author from {$tablepre}threads t, {$tablepre}posts p where t.fid=$fid and p.tid=t.tid and t.displayorder>=0 and p.invisible=0 and p.status=0 order by p.dateline DESC limit 1"; $query = $db->query($sql); $lastarray = array(); if($lastarray = $db->fetch_array($query)){ $lastarray['subject'] = $lastarray['psubject']?$lastarray['psubject']:$lastarray['subject']; $lastpoststr = $lastarray['tid']."\t".$lastarray['subject']."\t".$lastarray['dateline']."\t".$lastarray['author']; $db->query("update {$tablepre}forums set lastpost='$lastpoststr' where fid=$fid"); } } htmlheader(); show_tools_message("重置成功", 'tools.php?action=dz_rplastpost'); htmlfooter(); }else {//不存在更新的FID 进入选择界面 htmlheader(); ?>

    修复版块最后回复

    操作提示:
    • 可以指定需要修复的版块,提交后程序会重新查询出版块的最后回复信息并且修复
    "; ?>

    论坛版块列表

    全选
    您已成功退出,欢迎下次使用.强烈建议您在不使用时删除此文件."); } elseif ($action == 'all_toolsback') { htmlheader(); ?>

    欢迎您使用 Comsenz 系统维护工具箱


    Comsenz 系统维护工具箱功能简介:
    检查数据表 Checking table $table"; echo "TableOperationTypeText"; } else { if(!$simple) { echo "\n>>>>>>>>>>>>>Checking Table $table\n"; echo "---------------------------------
    \n"; } } $error = 0; while($r = mysql_fetch_row($result)) { if($r[2] == 'error') { if($r[3] == "The handler for the table doesn't support check/repair") { $r[2] = 'status'; $r[3] = 'This table does not support check/repair/optimize'; unset($bgcolor); $nooptimize = 1; } else { $error = 1; $bgcolor = 'red'; unset($nooptimize); } $view = '错误'; $errortables += 1; } else { unset($bgcolor); unset($nooptimize); $view = '正常'; if($r[3] == 'OK') { $oktables += 1; }elseif($r[3] == 'The storage engine for the table doesn\'t support check'){ $oktables += 1; } } if(!$nohtml) { echo "$r[0]$r[1]$r[2]$r[3] / $view "; } else { if(!$simple) { echo "$r[0] | $r[1] | $r[2] | $r[3]
    \n"; } } } if($error) { if(!$nohtml) { echo "正在修复中 / Repairing table $table"; } else { if(!$simple) { echo ">>>>>>>>正在修复中 / Repairing Table $table
    \n"; } } $result2=mysql_query("REPAIR TABLE $table"); while($r2 = mysql_fetch_row($result2)) { if($r2[3] == 'OK') { $bgcolor='blue'; $rapirtables += 1; } else { unset($bgcolor); } if(!$nohtml) { echo "$r2[0]$r2[1]$r2[2]$r2[3]"; } else { if(!$simple) { echo "$r2[0] | $r2[1] | $r2[2] | $r2[3]
    \n"; } } } } if(($result2[3]=='OK'||!$error)&&!$nooptimize) { if(!$nohtml) { echo "优化数据表 Optimizing table $table"; } else { if(!$simple) { echo ">>>>>>>>>>>>>Optimizing Table $table
    \n"; } } $result3=mysql_query("OPTIMIZE TABLE $table"); $error=0; while($r3=mysql_fetch_row($result3)) { if($r3[2]=='error') { $error=1; $bgcolor='red'; } else { unset($bgcolor); } if(!$nohtml) { echo "$r3[0]$r3[1]$r3[2]$r3[3]"; } else { if(!$simple) { echo "$r3[0] | $r3[1] | $r3[2] | $r3[3]

    \n"; } } } } if($error && $loops) { checktable($table,($loops-1)); } } function checkfullfiles($currentdir) { global $db, $tablepre, $md5files, $cachelist, $templatelist, $lang, $nopass; $dir = @opendir(TOOLS_ROOT.$currentdir); while($entry = @readdir($dir)) { $file = $currentdir.$entry; $file = $currentdir != './' ? preg_replace('/^\.\//', '', $file) : $file; $mainsubdir = substr($file, 0, strpos($file, '/')); if($entry != '.' && $entry != '..') { echo "\r\n"; if(is_dir($file)) { checkfullfiles($file.'/'); } elseif(is_file($file) && !in_array($file, $md5files)) { $pass = FALSE; if(in_array($file, array('./favicon.ico', './config.inc.php', './mail_config.inc.php', './robots.txt'))) { $pass = TRUE; } if($entry == 'index.htm' && filesize($file) < 5) { $pass = TRUE; } switch($mainsubdir) { case 'attachments' : if(!preg_match('/\.(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)$/i', $entry)) { $pass = TRUE; } break; case 'images' : if(preg_match('/\.(gif|jpg|jpeg|png|ttf|wav|css)$/i', $entry)) { $pass = TRUE; } case 'customavatars' : if(preg_match('/\.(gif|jpg|jpeg|png)$/i', $entry)) { $pass = TRUE; } break; case 'mspace' : if(preg_match('/\.(gif|jpg|jpeg|png|css|ini)$/i', $entry)) { $pass = TRUE; } break; case 'forumdata' : $forumdatasubdir = str_replace('forumdata', '', dirname($file)); if(substr($forumdatasubdir, 0, 8) == '/backup_') { if(preg_match('/\.(zip|sql)$/i', $entry)) { $pass = TRUE; } } else { switch ($forumdatasubdir) { case '' : if(in_array($entry, array('dberror.log', 'install.lock'))) { $pass = TRUE; } break; case '/templates': if(empty($templatelist)) { $query = mysql_query("SELECT templateid, directory FROM {$tablepre}templates"); while($template = mysql_fetch_array($query)) { $templatelist[$template['templateid']] = $template['directory']; } } $tmp = array(); $entry = preg_replace('/(\d+)\_(\w+)\.tpl\.php/ie', '$tmp = array(\1,"\2");', $entry); if(!empty($tmp) && file_exists($templatelist[$tmp[0]].'/'.$tmp[1].'.htm')) { $pass = TRUE; } break; case '/logs': if(preg_match('/(runwizardlog|\_cplog|\_errorlog|\_banlog|\_illegallog|\_modslog|\_ratelog|\_medalslog)\.php$/i', $entry)) { $pass = TRUE; } break; case '/cache': if(preg_match('/\.php$/i', $entry)) { if(empty($cachelist)) { $cachelist = checkcachefiles('forumdata/cache/'); foreach($cachelist[1] as $nopassfile => $value) { $nopass++; echo "\r\n"; } } $pass = TRUE; } elseif(preg_match('/\.(css|log)$/i', $entry)) { $pass = TRUE; } break; case '/threadcaches': if(preg_match('/\.htm$/i', $entry)) { $pass = TRUE; } break; } } break; case 'templates' : if(preg_match('/\.(lang\.php|htm)$/i', $entry)) { $pass = TRUE; } break; case 'include' : if(preg_match('/\.table$/i', $entry)) { $pass = TRUE; } break; case 'ipdata' : if($entry == 'wry.dat' || preg_match('/\.txt$/i', $entry)) { $pass = TRUE; } break; case 'admin' : if(preg_match('/\.md5$/i', $entry)) { $pass = TRUE; } break; } if(!$pass) { $nopass++; echo "\r\n"; } } ob_flush(); flush(); } } return $nopass; } function checkdirs($currentdir) { global $dirlist; $dir = @opendir(TOOLS_ROOT.$currentdir); while($entry = @readdir($dir)) { $file = $currentdir.$entry; if($entry != '.' && $entry != '..') { if(is_dir($file)) { $dirlist[] = $file; checkdirs($file.'/'); } } } } function checkcachefiles($currentdir) { global $authkey; $dir = opendir($currentdir); $exts = '/\.php$/i'; $showlist = $modifylist = $addlist = array(); while($entry = readdir($dir)) { $file = $currentdir.$entry; if($entry != '.' && $entry != '..' && preg_match($exts, $entry)) { @$fp = fopen($file, 'rb'); @$cachedata = fread($fp, filesize($file)); @fclose($fp); if(preg_match("/^<\?php\n\/\/Discuz! cache file, DO NOT modify me!\n\/\/Created: [\w\s,:]+\n\/\/Identify: (\w{32})\n\n(.+?)\?>$/s", $cachedata, $match)) { $showlist[$file] = $md5 = $match[1]; $cachedata = $match[2]; if(md5($entry.$cachedata.$authkey) != $md5) { $modifylist[$file] = $md5; } } else { $showlist[$file] = $addlist[$file] = ''; } } } return array($showlist, $modifylist, $addlist); } function continue_redirect($action = 'dz_mysqlclear', $extra = '') { global $scriptname, $step, $actionnow, $start, $end, $stay, $convertedrows, $allconvertedrows, $totalrows, $maxid; if($action == 'doctor') { $url = "?action=$action{$extra}"; } else { $url = "?action=$action&step=".$step."&start=".($end + 1)."&stay=$stay&totalrows=$totalrows&convertedrows=$convertedrows&maxid=$maxid&allconvertedrows=$allconvertedrows".$extra; } $timeout = $GLOBALS['debug'] ? 5000 : 2000; echo "\r\n"; if($action == 'doctor') { echo '

    论坛医生


    正在进行检查,请稍候
    '; echo "
    如果您的浏览器长时间没有自动跳转,请点击这里!

    "; echo '
    '; } elseif($action == 'dz_replace') { echo '

    数据处理中

    正在进行'.$actionnow.'
    '; echo "正在处理 $start ---- $end 条数据[停止运行]"; echo "

    如果您的浏览器长时间没有自动跳转,请点击这里!"; echo '
    '; } else { echo '

    数据处理中

    正在进行'.$actionnow.'
    '; echo "正在处理 $start ---- $end 条数据[停止运行]"; echo "

    如果您的浏览器长时间没有自动跳转,请点击这里!"; echo '
    '; } } function dirsize($dir) { $dh = @opendir($dir); $size = 0; while($file = @readdir($dh)) { if ($file != '.' && $file != '..') { $path = $dir.'/'.$file; if (@is_dir($path)) { $size += dirsize($path); } else { $size += @filesize($path); } } } @closedir($dh); return $size; } function get_real_size($size) { $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($size < $kb) { return $size.' Byte'; } else if($size < $mb) { return round($size/$kb,2).' KB'; } else if($size < $gb) { return round($size/$mb,2).' MB'; } else if($size < $tb) { return round($size/$gb,2).' GB'; } else { return round($size/$tb,2).' TB'; } } function htmlheader(){ global $alertmsg, $whereis, $functionall; echo ' Comsenz 系统维护工具箱 3.0UC
    '; } function htmlfooter(){ echo '
    '; exit; } function errorpage($message,$title = '',$isheader = 1,$isfooter = 1){ if($isheader) { htmlheader(); } !$isheader && $title = ''; if($message == 'login'){ $message ='

    工具箱登录

    '; } else { $message = "

    $title



    提示信息
    $message
    "; } echo $message; if($isfooter) { htmlfooter(); } } function redirect($url) { echo ""; echo "

    如果您的浏览器没有自动跳转,请点击这里"; cexit(""); } /** * 检查目录里下的文件权限函数 * * @param unknown_type $directory */ function getdirentry($directory) { global $entryarray; $dir = dir('./'.$directory); while($entry = $dir->read()) { if($entry != '.' && $entry != '..') { if(is_dir('./'.$directory.'/'.$entry)) { $entryarray[] = $directory.'/'.$entry; getdirentry($directory."/".$entry); } else { $entryarray[] = $directory.'/'.$entry; } } } $dir->close(); } function splitsql($sql){ $sql = str_replace("\r", "\n", $sql); $ret = array(); $num = 0; $queriesarray = explode(";\n", trim($sql)); unset($sql); foreach($queriesarray as $query) { $queries = explode("\n", trim($query)); foreach($queries as $query) { $ret[$num] .= $query[0] == "#" ? NULL : $query; } $num++; } return($ret); } function syntablestruct($sql, $version, $dbcharset) { if(strpos(trim(substr($sql, 0, 18)), 'CREATE TABLE') === FALSE) { return $sql; } $sqlversion = strpos($sql, 'ENGINE=') === FALSE ? FALSE : TRUE; if($sqlversion === $version) { return $sqlversion && $dbcharset ? preg_replace(array('/ character set \w+/i', '/ collate \w+/i', "/DEFAULT CHARSET=\w+/is"), array('', '', "DEFAULT CHARSET=$dbcharset"), $sql) : $sql; } if($version) { return preg_replace(array('/TYPE=HEAP/i', '/TYPE=(\w+)/is'), array("ENGINE=MEMORY DEFAULT CHARSET=$dbcharset", "ENGINE=\\1 DEFAULT CHARSET=$dbcharset"), $sql); } else { return preg_replace(array('/character set \w+/i', '/collate \w+/i', '/ENGINE=MEMORY/i', '/\s*DEFAULT CHARSET=\w+/is', '/\s*COLLATE=\w+/is', '/ENGINE=(\w+)(.*)/is'), array('', '', 'ENGINE=HEAP', '', '', 'TYPE=\\1\\2'), $sql); } } function stay_redirect() { global $action, $actionnow, $step, $stay, $convertedrows, $allconvertedrows; $nextstep = $step + 1; echo '

    数据库冗余数据清理

    正在进行'.$actionnow.'
    '; if($stay) { $actions = isset($action[$nextstep]) ? $action[$nextstep] : '结束'; echo "$actionnow 操作完毕.共处理{$convertedrows}条数据.".($stay == 1 ? "    " : '').'

    '; echo "如果继续下一步操作( $actions ),请点击这里!
    "; } else { if(isset($action[$nextstep])) { echo '即将进入:'.$action[$nextstep].'......'; } $allconvertedrows = $allconvertedrows + $convertedrows; $timeout = $GLOBALS['debug'] ? 5000 : 2000; echo "\r\n"; echo "[停止运行]

    如果您的浏览器长时间没有自动跳转,请点击这里!"; } echo '
    '; } function loadtable($table, $force = 0) { //检查数据库表字符集函数 global $carray; $discuz_tablepre = $carray['tablepre']; static $tables = array(); if(!isset($tables[$table])) { if(mysql_get_server_info() > '4.1') { $query = @mysql_query("SHOW FULL COLUMNS FROM {$discuz_tablepre}$table"); } else { $query = @mysql_query("SHOW COLUMNS FROM {$discuz_tablepre}$table"); } while($field = @mysql_fetch_assoc($query)) { $tables[$table][$field['Field']] = $field; } } return $tables[$table]; } function validid($id, $table) {//获得数据表的最大和最小 id 值 global $start, $maxid, $db, $tablepre; $sql = $db->query("SELECT MIN($id) AS minid, MAX($id) AS maxid FROM {$tablepre}$table"); $result = $db->fetch_array($sql); $start = $result['minid'] ? $result['minid'] - 1 : 0; $maxid = $result['maxid']; } function specialdiv() { echo '
    注意:
    • 对数据库操作可能会出现意外现象的发生及破坏,所以请先备份好数据库再进行上述操作!另外请您选择服务器压力比较小的时候进行一些优化操作。
    • 当您使用完毕Comsenz 系统维护工具箱后,请点击锁定工具箱以确保系统的安全!下次使用前只需要在/forumdata目录下删除tool.lock文件即可开始使用。
    '; } function getplace() { global $lockfile, $cfgfile; $whereis = false; if(is_writeable('./config.inc.php') && is_writeable('./forumdata')) {//判断Discuz!目录 $whereis = 'is_dz'; $lockfile = './forumdata/tools.lock'; $cfgfile = './config.inc.php'; } if(is_writeable('./data/config.inc.php') && is_dir('./control')) {//判断UCenter目录 $whereis = 'is_uc'; $lockfile = './data/tools.lock'; $cfgfile = './data/config.inc.php'; } if(is_writeable('./config.php') && is_dir('source')) {//判断UCenter Home目录 $whereis = 'is_uch'; $lockfile = './data/tools.lock'; $cfgfile = './config.php'; } if(is_writeable('./config.php') && file_exists('./batch.common.php')) {//判断SupeSite目录 $whereis = 'is_ss'; $lockfile = './data/tools.lock'; $cfgfile = './config.php'; } if(is_writeable('./data/config.php')) {//判断ECShop目录 $cfgpage = file_get_contents('./data/config.php'); if(strpos($cfgpage, 'EC_CHARSET')) { $whereis = 'is_ec'; $lockfile = './data/tools.lock'; $cfgfile = './data/config.php'; } } if(is_writeable('./data/inc.config.php')) {//判断ECmall目录 $cfgpage = file_get_contents('./data/inc.config.php'); if(strpos($cfgpage, 'ECM_KEY')) { $whereis = 'is_ecm'; $lockfile = './data/tools.lock'; $cfgfile = './data/inc.config.php'; } } return $whereis; } function getdbcfg(){//获得数据库配置信息 global $dbhost, $dbuser, $dbpw, $dbname, $dbcfg, $whereis, $cfgfile, $tablepre, $dbcharset; if(@!include($cfgfile)) { htmlheader(); cexit("

    请先上传config文件以保证您的数据库能正常链接!

    "); } switch($whereis) { case 'is_dz': $dbhost = $dbhost; $dbuser = $dbuser; $dbpw = $dbpw; $dbname = $dbname; $tablepre = $tablepre; $dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset): $dbcharset; break; case 'is_uc': $dbhost = UC_DBHOST; $dbuser = UC_DBUSER; $dbpw = UC_DBPW; $dbname = UC_DBNAME; $tablepre = UC_DBTABLEPRE; $dbcharset = !UC_DBCHARSET ? (strtolower(UC_CHARSET) == 'utf-8' ? 'utf8' : UC_CHARSET) : UC_DBCHARSET; break; case 'is_uch': $dbhost = $_SC["dbhost"]; $dbuser = $_SC["dbuser"]; $dbpw = $_SC["dbpw"]; $dbname = $_SC["dbname"]; $tablepre = $_SC["tablepre"]; $dbcharset = !$_SC['dbcharset'] ? (strtolower($_SC["charset"]) == 'utf-8' ? 'utf8' : $_SC["charset"]) : $_SC['dbcharset'] ; break; case 'is_ss': $dbhost = $dbhost; $dbuser = $dbuser; $dbpw = $dbpw; $dbname = $dbname; $pre = $tablepre; $dbcharset = !$dbcharset ? (strtolower($charset) == 'utf-8' ? 'utf8' : $charset) : $dbcharset; break; case 'is_ec': $dbhost = $db_host; $dbuser = $db_user; $dbpw = $db_pass; $dbname = $db_name; $tablepre = $prefix; $dbcharset = strtolower(EC_CHARSET) == 'utf-8' ? 'utf8' : EC_CHARSET; break; case 'is_ecm': $dbcfgs = parse_url(DB_CONFIG); $dbhost = $dbcfgs['host']; $dbuser = $dbcfgs['user']; $dbpw = $dbcfgs['pass']; $dbname = substr($dbcfgs['path'], 1); $tablepre = DB_PREFIX; $dbcharset = substr(LANG, strpos(LANG, '-')+1); break; default: $dbhost=$dbuser=$dbpw=$dbname=$tablepre=$dbcharset=''; break; } } function taddslashes($string, $force = 0) { !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()); if(!MAGIC_QUOTES_GPC || $force) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = taddslashes($val, $force); } } else { $string = addslashes($string); } } return $string; } function pregcharset($charset,$color=0) { if(strpos('..'.strtolower($charset), 'gbk')) { if($color){ return 'gbk'; }else{ return 'gbk'; } }elseif(strpos('..'.strtolower($charset), 'latin1')) { if($color){ return 'latin1'; }else{ return 'latin1'; } }elseif(strpos('..'.strtolower($charset), 'utf8')) { if($color){ return 'utf8'; }else{ return 'utf8'; } }elseif(strpos('..'.strtolower($charset), 'big5')) { if($color){ return 'big5'; }else{ return 'big5'; } }else{ return $charset; } } function show_tools_message($message, $url = 'tools.php') { echo ""; echo "

    $title



    提示信息
    $message
    如果您的浏览器没有自动跳转,请点击这里
    "; exit(""); } function fileext($filename) { return trim(substr(strrchr($filename, '.'), 1, 10)); } ?>